package Date和DateFormat编程题;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class CountDaysFromBirthday {
    public static void countDays() throws Throwable{
        Scanner in = new Scanner(System.in);
        System.out.println("Enter birthday:(eg:2022-06-18)");
        String birthday = in.nextLine();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date birthdayDate = sdf.parse(birthday);
        if(!birthdayDate.before(new Date())) {
            System.out.println("生日必须要早于当前日期!");
            System.exit(0);
        }
        long diff = new Date().getTime()-birthdayDate.getTime();
        int lived = (int) (diff/(1000*60*60*24));
        System.out.println("他来到世间:"+lived+"天");
    }
    public static void main(String[] args) throws Throwable{
        CountDaysFromBirthday.countDays();
    }
}
